
#include "EmployeeAemDbSaver.h"
#include "../../../../DAO/OdbcConnectionSingleton/OdbcConnectionSingleton.h"
#include "../../../../DAO/DbElementProvider/DbElementProvider.h"

EmployeeAemDbSaver::EmployeeAemDbSaver(){

	const string DB_NAME = *DbElementProvider::getInstance()->getDbName();
	const string USERNAME = *DbElementProvider::getInstance()->getUsername();
	const string PASSWORD = *DbElementProvider::getInstance()->getPassword();

	bool connectionEstablished = OdbcConnectionSingleton::getInstance()->connect(&DB_NAME,&USERNAME,&PASSWORD);
	if(false==connectionEstablished){
		throw;
	}
}


EmployeeAemDbSaver::EmployeeAemDbSaver(const string * dbName, const string * username, const string * password){

	if((0!=dbName)&&(0!=username)&&(0!=password)){
		bool ret =  OdbcConnectionSingleton::getInstance()->connect(dbName,username,password);
		if(!ret){
			string message = "Connection to " + (*dbName) + " failed!";
			//throw ConnectionFailed("Connection to "+()+);
		}
	}
}

//*
//	 *
EmployeeAemDbSaver::~EmployeeAemDbSaver(){

	// TODO Auto-generated destructor stub
}

//*
//	 *
bool EmployeeAemDbSaver::saveAem(const string * aem) {

	if(0!=aem){
		SQLHANDLE 	stmtHandle=OdbcConnectionSingleton::getInstance()->getStmtHandle();
		SQLRETURN	rc;

		bool isOk=false;

		string sqlString = "INSERT INTO employees VALUES ('" + *aem + "');";

		rc = SQLExecDirect(stmtHandle, (SQLTCHAR *)sqlString.c_str(), SQL_NTS);
		if(rc==SQL_SUCCESS){
			isOk=true;
		}
		SQLFreeHandle(SQL_HANDLE_STMT, stmtHandle);
		return isOk;
	}
}

